package com.heifeng.cloudshelf.base;

import android.os.Bundle;
import androidx.annotation.Nullable;
import android.view.View;


import com.heifeng.cloudshelf.di.component.DaggerFragmentComponent;
import com.heifeng.cloudshelf.di.component.FragmentComponent;
import com.heifeng.cloudshelf.di.module.FragmentModule;

import javax.inject.Inject;

/**
 * MVP Fragment基类
 */
public abstract class BaseFragment<P extends IBasePresenter> extends SimpleFragment implements IBaseView {

    @Inject
    protected P mPresenter;//dagger2依赖注入

    protected FragmentComponent getFragmentComponent() {
        return DaggerFragmentComponent.builder()
                .appComponent(MyApp.getAppComponent())
                .fragmentModule(getFragmentModule())
                .build();
    }

    protected FragmentModule getFragmentModule() {
        return new FragmentModule(this);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        initInject();
        mPresenter.attachView(mContext, this);
        super.onViewCreated(view, savedInstanceState);
    }


    @Override
    public void onDestroyView() {
        if (mPresenter != null) mPresenter.detachView();
        super.onDestroyView();
    }


    @Override
    public void useNightMode(boolean isNight) {

    }

    protected abstract void initInject();
}